package com.yyfax.ph.common.widgets.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.yyfax.ph.R;
import com.yyfax.ph.main.MainModel;

/**
 * 项目名称：yjyc1.1.0
 * 类描述：
 * 创建人：xiongyuefng
 * 创建时间：2016/12/22 19:11
 * 修改人：xiongyufeng
 * 修改时间：2016/12/22 19:11
 * 修改备注：
 */
public class NoticeDialog extends Dialog implements View.OnClickListener, DialogInterface.OnDismissListener {

	@BindView(R.id.notice_title_tv)
	TextView mTitleTv;
	@BindView(R.id.notice_content_tv)
	TextView mContentTv;
	private CloseNoticeListener mCloseNoticeListener;
	private MainModel.NoticeBean mNoticeBean;


	public interface CloseNoticeListener {
		void onCloseNoticeDialog(String noticeId);
	}


	public NoticeDialog(Context context) {
		super(context, R.style.progress_style);
		setCancelable(false);
		setCanceledOnTouchOutside(false);
	}

	public NoticeDialog(Context context, MainModel.NoticeBean noticeBean, CloseNoticeListener closeNoticeListener) {
		this(context);
		mNoticeBean = noticeBean;
		mCloseNoticeListener = closeNoticeListener;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_notice_layout);
		ButterKnife.bind(this);
		initView();
		initWindowParams();
	}

	private void initView() {
		mTitleTv.setText(mNoticeBean.title);
		mContentTv.setText(mNoticeBean.content);
	}

	@Override
	public void onDismiss(DialogInterface dialogInterface) {
		if (null != getWindow()) {
			WindowManager.LayoutParams params = getWindow().getAttributes();
			params.alpha = 1f;
			getWindow().setAttributes(params);
		}
	}

	@OnClick(R.id.btn_confirm)
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.btn_confirm:
				if (null != mCloseNoticeListener) {
					mCloseNoticeListener.onCloseNoticeDialog(mNoticeBean.id);
				}
				dismiss();
				break;
		}
	}

	private void initWindowParams() {
		Window window = getWindow();
		if (null != window) {
			window.setWindowAnimations(R.style.AnimBottom);
			ColorDrawable dw = new ColorDrawable(0x40000000);
			window.setBackgroundDrawable(dw);
			window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
			WindowManager.LayoutParams params = window.getAttributes();
			params.alpha = 1.0f;
			window.setAttributes(params);
		}


	}
}
